{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn import metrics\n",
    "from sklearn import ensemble\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.preprocessing import Imputer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "df = pd.read_csv('data/titanic/train.csv',index_col='PassengerId')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.concat([df,pd.get_dummies(df['Pclass'], prefix='Pclass')],axis=1)\n",
    "df.drop(['Pclass'],axis=1,inplace=True)\n",
    "df = pd.concat([df,pd.get_dummies(df['Sex'], prefix='Sex')],axis=1)\n",
    "df.drop(['Sex'],axis=1,inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train = train_df[['Pclass_1','Pclass_2','Pclass_3', 'Sex_female','Sex_male','Age','Fare']].values\n",
    "\n",
    "imp = Imputer(missing_values='NaN', strategy='mean', axis=0)\n",
    "X_train =imp.fit_transform(X_train)\n",
    "\n",
    "y_train = train_df[['Survived']].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_test = test_df[['Pclass_1','Pclass_2','Pclass_3', 'Sex_female','Sex_male','Age','Fare']].values\n",
    "\n",
    "X_test = imp.transform(X_test)\n",
    "\n",
    "y_test = test_df[['Survived']].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "GradientBoostingClassifier(criterion='friedman_mse', init=None,\n",
       "              learning_rate=0.1, loss='deviance', max_depth=3,\n",
       "              max_features=None, max_leaf_nodes=None,\n",
       "              min_impurity_decrease=0.0, min_impurity_split=None,\n",
       "              min_samples_leaf=1, min_samples_split=2,\n",
       "              min_weight_fraction_leaf=0.0, n_estimators=100,\n",
       "              presort='auto', random_state=None, subsample=1.0, verbose=0,\n",
       "              warm_start=False)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf = ensemble.GradientBoostingClassifier()\n",
    "clf.fit(X_train, y_train.ravel())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEWCAYAAACJ0YulAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xl4VdXVx/HvIgqIgspQB6ZgARUQ\nEBCL1jorOOCMUAdQlFZrVdS2OFtqq1brbKtgnRVUVESL4oRTq2IcQAiKCEGDvgIBERMCJFnvH/sk\nxJjhZrhT8vs8Tx7uOffce9cJkJU9rW3ujoiICECzZAcgIiKpQ0lBRETKKCmIiEgZJQURESmjpCAi\nImWUFEREpIySgoiIlFFSkEbFzHLMbL2Z/WBm/2dmD5jZNhWu2cfMXjOzdWa21syeM7NeFa5pY2a3\nmtmX0Xt9ER23r+JzzczON7P5ZpZvZrlm9qSZ7RHP+xVpaEoK0hgd7e7bAP2BPYFLS58wsyHAS8Cz\nwM5AN2Au8F8z2yW6pjnwKtAbGAq0AYYAecDgKj7zNuAC4HygLdATmA4cWdvgzWyL2r5GpKGYVjRL\nY2JmOcBZ7v5KdPx3oLe7HxkdvwV84u7nVnjdC8BKdz/dzM4C/gr83N1/iOEzewCfAkPcfU4V17wO\nPOLu90bHY6I4fxkdO3AecCGwBfAikO/ul5R7j2eBN9z9ZjPbGbgD+BXw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pKioiKysLgGnTpvHVV6Envl+/fjz99NMAzJkz\nh2XLlpGbm1tjjLURt5aCuxeZ2XnALCADuM/dF5jZRCDL3WcA/wYeNrPFwGpC4hCRRqim3+jjZcqU\nKWXdLCNHjmTKlCkMHDiwylk6tZ3rcsstt9Q7xoqfP3XqVMaPH8+GDRs47LDDyMjIAGDChAlccMEF\n9O/fnz322IM999yz7LmGEtfFa+4+E5hZ4dxV5R4XAifFMwYRabpWr17Na6+9xieffIKZUVxcjJlx\n44030q5dO9asWfOT69u3b0/37t358ssv+f7772tsLYwfP57Zs2f/5PzIkSPLunpKdezYsey3fgiL\n+zpWMm45ZMgQ3nrrLQBeeuklFi1aBECbNm24//77gbBQrVu3buzS0OV13D2tvgYOHOgikh6ys7OT\n+vn33HOPjxs37kfnfvWrX/kbb7zhhYWFnpmZWRZjTk6Od+nSxb/77jt3d//DH/7gY8aM8Q0bNri7\n+4oVK/yJJ56oVzzz58/3vn37emFhoS9ZssS7devmRUVFP7nu22+/dXf3wsJCP+igg/zVV191d/c1\na9aUxTNp0iQ/7bTTKv2cyr7vhB6aGn/GpsXsIxGRupgyZQrHHXfcj86dcMIJTJkyhRYtWvDII49w\nxhln0L9/f0488UTuvfdett12WwCuvfZaOnToQK9evejTpw9HHXVUTGMM1enduzcjRoygV69eDB06\nlLvuuqus++eII47g66+/BuDGG29k9913p2/fvhx99NEcdNBBACxcuJA+ffqw66678sILL3DbbbfV\nK57KmKfZuO6gQYO8dABGRFLbwoUL2X333ZMdRpNT2ffdzD5w90E1vVYtBRERKaOkICIiZZQURCSu\n0q2LOt3V9/utpCAicdOyZUvy8vKUGBLEo/0UWrZsWef30CY7IhI3nTp1Ijc3l4QWsmziSndeqysl\nBRGJmy233LLOO4BJcqj7SEREyigpiIhIGSUFEREpk3Yrms1sJbAsgR/ZHliVwM9LNN1f+mrM9wa6\nv4bW1d1r3KUs7ZJCoplZVixLw9OV7i99NeZ7A91fsqj7SEREyigpiIhIGSWFmk1KdgBxpvtLX435\n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LPu0fFpwBtRH/y2\n7j6TkKz6VfLadYSy3ZV5hrDj1ihCgqC2cUYF4a4EfmFmuxF2JssH1prZDsCwKmJ5F9i39J7MbGsz\nq6zVJU2UkoKki38Co81sLqHLJb+Sa0YA883sY8IeCg9FM36uAF4ys3nAy4SulRq5eyGhauWTZvYJ\nUALcTfgB+3z0fm9TeZ/8A8DdpQPNFd53DbAQ6Oruc6JztY4zGqv4B6Eq6lzCPs2fAo8RuqRKTQJe\nNLPZ7r6SMDNqSvQ57xC+nyKAqqSKiEg5aimIiEgZJQURESmjpCAiImWUFEREpIySgoiIlFFSEBGR\nMkoKIiJS5v8BBNTORquvufQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7ff7d4fd24e0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "y_preds = clf.predict_proba(X_test)\n",
    "\n",
    "# take the second column because the classifier outputs scores for\n",
    "# the 0 class as well\n",
    "preds = y_preds[:,1]\n",
    "\n",
    "# fpr means false-positive-rate\n",
    "# tpr means true-positive-rate\n",
    "fpr, tpr, _ = metrics.roc_curve(y_test, preds)\n",
    "\n",
    "auc_score = metrics.auc(fpr, tpr)\n",
    "\n",
    "plt.title('ROC Curve')\n",
    "plt.plot(fpr, tpr, label='AUC = {:.2f}'.format(auc_score))\n",
    "\n",
    "# it's helpful to add a diagonal to indicate where chance \n",
    "# scores lie (i.e. just flipping a coin)\n",
    "plt.plot([0,1],[0,1],'r--')\n",
    "\n",
    "plt.xlim([-0.1,1.1])\n",
    "plt.ylim([-0.1,1.1])\n",
    "plt.ylabel('True Positive Rate')\n",
    "plt.xlabel('False Positive Rate')\n",
    "\n",
    "plt.legend(loc='lower right')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.  ,  0.  ,  0.29,  0.15,  0.19,  0.14,  0.23])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf.feature_importances_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>feature</th>\n",
       "      <th>importance</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Pclass_3</td>\n",
       "      <td>0.29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Fare</td>\n",
       "      <td>0.23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Sex_male</td>\n",
       "      <td>0.19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Sex_female</td>\n",
       "      <td>0.15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Age</td>\n",
       "      <td>0.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Pclass_1</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Pclass_2</td>\n",
       "      <td>0.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      feature  importance\n",
       "2    Pclass_3        0.29\n",
       "6        Fare        0.23\n",
       "4    Sex_male        0.19\n",
       "3  Sex_female        0.15\n",
       "5         Age        0.14\n",
       "0    Pclass_1        0.00\n",
       "1    Pclass_2        0.00"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame({\n",
    "    'feature':['Pclass_1','Pclass_2','Pclass_3', 'Sex_female','Sex_male','Age','Fare'],\n",
    "    'importance':clf.feature_importances_\n",
    "}).sort_values(\"importance\",ascending=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Global TF Kernel (Python 3)",
   "language": "python",
   "name": "global-tf-python-3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
